<template>
  <div>
    <!-- 弹出层的头部区域 -->
    <van-nav-bar title="频道管理">
      <template #right>
        <van-icon
          name="cross"
          size="0.37333334rem"
          color="white"
          @click="goChannel('关闭')"
        />
      </template>
    </van-nav-bar>
    <!-- 我的频道 -->
    <div class="my-channel-box">
      <div class="channel-title">
        <span
          >我的频道
          <span class="small-title"> 点击进入频道 </span>
        </span>
        <span @click="textChange">{{ textflag ? '完成' : '编辑' }}</span>
      </div>
      <!-- 我的频道列表 -->
      <van-row type="flex">
        <van-col
          span="6"
          v-for="obj in UserChannel"
          :key="obj.id"
          @click="goChannel(obj.id)"
        >
          <div class="channel-item van-hairline--surround">
            {{ obj.name }}
            <!-- 删除的徽标 -->
            <van-badge color="transparent" class="cross-badge">
              <template #content>
                <van-icon
                  name="cross"
                  class="badge-icon"
                  color="#cfcfcf"
                  size="0.32rem"
                  v-if="textflag && obj.id !== 0"
                  @click="delChannel(obj)"
                />
              </template>
            </van-badge>
          </div>
        </van-col>
      </van-row>
    </div>

    <!-- 更多频道 -->
    <div class="more-channel-box">
      <div class="channel-title">
        <span>点击添加更多频道：</span>
      </div>
      <!-- 更多频道列表 -->
      <van-row type="flex">
        <van-col
          span="6"
          v-for="obj in NotSelectedChannel"
          :key="obj.id"
          @click="addChannel(obj)"
        >
          <div class="channel-item van-hairline--surround">{{ obj.name }}</div>
        </van-col>
      </van-row>
    </div>
  </div>
</template>

<script>
export default {
  props: ['UserChannel', 'NotSelectedChannel'],
  data() {
    return {
      textflag: false, // 控制编辑按钮的文字切换 false为编辑 true为完成
    }
  },
  methods: {
    // 点击编辑按钮
    textChange() {
      this.textflag = !this.textflag
    },
    // 添加频道
    addChannel(str) {
      // 点击了编辑按钮后 才可以添加频道
      if (this.textflag) {
        this.$emit('addChannel', str)
      }
    },
    // 删除频道
    delChannel(str) {
      // 点击了编辑按钮后 才可以删除频道
      if (this.textflag) {
        this.$emit('delChannel', str)
      }
    },
    // 进入频道
    goChannel(id) {
      // console.log(id)
      // console.log(this.textflag)
      if (!this.textflag && id !== '关闭') {
        console.log('直接进去频道')
        this.$emit('goChannel', id)
      } else if (id === '关闭') {
        console.log('关闭弹出层')
        this.$emit('goChannel', id)
      }
    },
  },
}
</script>

<style scoped lang="less">
/deep/ .van-nav-bar__title {
  color: #fff;
}
.my-channel-box,
.more-channel-box {
  .channel-title {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    line-height: 28px;
    padding: 0 6px;
  }
}

.channel-item {
  font-size: 12px;
  text-align: center;
  line-height: 36px;
  background-color: #fafafa;
  margin: 5px;
}

/*删除的微标 */
.cross-badge {
  position: absolute;
  right: -3px;
  top: 0;
  border: none;
}

/*提示文字 */
.small-title {
  font-size: 10px;
  color: gray;
}
</style>
